<style lang="less">
    @import './login.less';
</style>

<template>
    <div class="login" @keydown.enter="handleSubmit">
        <div class="login-con">
            <Card :bordered="false">
                <p slot="title">
                    <Icon type="log-in"></Icon>
                    欢迎登录
                </p>
                <div class="form-con">
                    <Form ref="loginForm" :model="form" :rules="rules">
                        <FormItem prop="userName">
                            <Input v-model="form.userName" placeholder="请输入Email/考号">
                                <span slot="prepend">
                                    <Icon :size="16" type="person" style="color: #A8E037"></Icon>
                                </span>
                            </Input>
                        </FormItem>
                        <FormItem prop="password">
                            <Input type="password" v-model="form.password" placeholder="请输入密码">
                                <span slot="prepend">
                                    <Icon :size="14" type="locked" style="color: #A8E037"></Icon>
                                </span>
                            </Input>
                        </FormItem>
                        <FormItem>
                            <Button @click="handleSubmit" type="primary" long>登录</Button>
                        </FormItem>
                    </Form>
                    <Row >
                        <Col class-name="register-tip"  span="12"><Button @click="register" type="text">立即注册</Button></Col>
                        <Col class-name="password-tip" span="12"><Button  type="text">找回密码</Button></Col>
                    </Row>
                </div>
            </Card>
        </div>
    </div>
</template>

<script>
import Cookies from 'js-cookie';
import {exam} from '../../api/index.js';
export default {
    data () {
        return {
            form: {
                userName: "",
                password: ""
            },
            rules: {
                userName: [
                    { required: true, message: '账号不能为空', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '密码不能为空', trigger: 'blur' }
                ]
            }
        };
    },
    methods: {
        handleSubmit () {
            this.$refs.loginForm.validate((valid) => {
                if (valid) {
                    exam.login_post({"data": {"userName": this.form.userName,"password":this.form.password }}).then((res)=> {
                        if(res.data.resCode!=0){
                                this.$Message.error(res.data.resMsg);
                        }else{
                            let email = res.data.data.user.email;
                            let status = res.data.data.user.userStatus;
                            if(status==0){
                                this.$router.push({
                                    name: 'portal_regist',
                                    params: { email: email,status:status }
                                });
                            }else if(status==1){
                                this.$router.push({
                                    name: 'portal_regist',
                                    params: { email: email,status:status,student: res.data.data.student }
                                });
                            }
                            else if(status==2){
                                this.$router.push({
                                        name: 'home_index'
                                });
                            }
                        }
                    }, function (error) {
                        alert("系统异常，请先联系管理员");
                    });

                    //Cookies.set('user', this.form.userName);
                   // Cookies.set('password', this.form.password);
                   // if (this.form.userName === 'iview_admin') {
                   //     Cookies.set('access', 0);
                  //  } else {
                   //     Cookies.set('access', 1);
                    //}

                }
            });
        },
        register(){
            this.$router.push({
                name: 'portal_regist'
            });
        }
    }
};
</script>

<style>

</style>
